package com.zzh.tree;

public class No230_kthSmallest {
    public static void main(String[] args) {
        No230Solution solution = new No230Solution();
        int i = solution.kthSmallest(TreeNode.initTree(), 2);
        System.out.println(i);
    }
}
class No230Solution{
    private int cnt;
    private int a;
    private int f;
    public int kthSmallest(TreeNode root, int k) {
        f=k;
        kth(root);
        return a;
    }
    private void kth(TreeNode root){
        if (root==null){
            return;
        }
        kth(root.left);
        //对应二叉搜索树来说，中序遍历就是按升序排列的
        cnt++;
        if (cnt==f){
            a=root.val;
            return;
        }
        kth(root.right);
    }
}
